package com.baizhi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping("selectAll")
    public String selectAll(){
        String url="http://product-module/selectOne/1";
//        String result = restTemplate.getForObject(url, String.class);
//        System.out.println(result);
        //这个方法跟上面的getForObject作用一样都是跨服务获取结果，该方法获取到的结果被封装到了responseEntity里面
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        String result = forEntity.getBody();//获取到的是响应体信息
        HttpStatus statusCode = forEntity.getStatusCode();//获取到的是响应的状态码
        System.out.println(statusCode);
//在查询用户信息的同时调用商品模块，查询商品的信息
        System.out.println("我是userController里面的selectAll方法");
        return "UserController-selectAll"+result;
    }
}
